<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 使用数组模型把学生数据模拟出来. -->
    <!-- 动态创建行.单元格式 -->
    <!-- 67  -->
    <!-- 我靠这个看着好难 -->
    <style>
        body {
            width: 100%;
            margin: 0 auto;
            height: 300px;
            position: fixed;
        }
        
        table {
            width: 500px;
            height: auto;
            position: relative;
            left: 50%;
            margin-left: -250px;
            justify-content: center;
            align-content: center;
            align-items: center;
        }
        
        tr {
            display: flex;
            justify-content: center;
            align-content: center;
            align-items: center;
            border-bottom: 1px solid #333;
            text-align: center;
        }
        
        td,
        th {
            flex: 1;
        }
        
        thead tr {
            height: 40px;
            background-color: #ccc;
        }
    </style>
</head>

<body>
    <table cellspacing="0">
        <thead>
            <tr>
                <th>姓名</th>
                <th>科目</th>
                <th>成绩</th>
                <th>操作</th>
            </tr>
        </thead>

        <tbody>
        </tbody>

    </table>

    <script>
        var datas = [{
            name: '张三',
            subject: 'JavaScript',
            score: 100
        }, {
            name: '李四',
            subject: 'JavaScript',
            score: 90
        }, {
            name: '刘五',
            subject: 'JavaScript',
            score: 90
        }];

        var tbody = document.querySelector('tbody');
        for (var i = 0; i < datas.length; i++) {

            var tr = document.createElement('tr');
            tbody.appendChild(tr);
            //2.
            for (var k in datas[i]) {

                var td = document.createElement('td');

                td.innerHTML = datas[i][k];
                tr.appendChild(td);
            }

            //3.创建有删除2个字的单元格
            var td = document.createElement('td');
            td.innerHTML = '<a href="JavaScript:;">删除</a>';
            tr.appendChild(td);
        }
        // 4.删除操作 开始
        var as = document.querySelectorAl1('a');
        for (var i = 0; i < as.length; i++) {
            as[i].onclick = function() {

                tbody.removeChild(this.parentNode.parentNode)
            }
        }
        // for (var k in obj) {
        //     k 得到的是属性名
        //     obj[k] 得到是属性值
        // }
    </script>
</body>

</html>